package com.example.mylibrary;

import static android.content.ContentValues.TAG;
import android.app.Instrumentation;
import android.util.Log;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class Cashbook {
    Instrumentation instrumentation=null;
    UiDevice device=null;
    @Before
    public void initInstrumentation() throws InterruptedException {
        Log.i(TAG,"连接设备");
        instrumentation=
                InstrumentationRegistry.getInstrumentation();
        device=UiDevice.getInstance(instrumentation);
        device.pressHome();
        UiObject2 icon1=device.findObject
                (By.text("CashBook"));
        icon1.click();
        Thread.sleep(3000);
    }
    //1、注册账号
    private void Register() throws InterruptedException {
        device.findObject(By.res("com.lyc.cashbook:id/register")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_account")).setText("111");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_psw")).setText("111");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_psw_again")).setText("111");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/register")).click();
    }

    //2、登录账号
    private void Login() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_account")).setText("111");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_psw")).setText("111");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/login")).click();
    }

    //3、我的——设置年预算确定操作
    @Test
    public void testYear1() throws InterruptedException {
        Register();
        Login();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/wd")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/tv_year_ys")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/button2")).click();
        Thread.sleep(1000);
    }

    //4、我的——设置年预算取消操作
	@Test
    public void testYear2() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/tv_year_ys")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/button3")).click();
        Thread.sleep(1000);
    }
	//5、我的——设置月预算确定操作
    @Test
    public void testMonth1() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/tv_month_ys")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/button2")).click();
        Thread.sleep(1000);
    }
	//6、我的——设置月预算取消操作
    @Test
    public void testMonth2() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/tv_month_ys")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/button3")).click();
        Thread.sleep(1000);
    }
	//7、我的-退出登录
	@Test
    public void test() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:text/\"退出登录\"")).click();
    }
	//8、菜单-关于
    @Test
    public void testMenu() throws InterruptedException {
        Register();
        Login();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"更多选项\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"关于\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/button2")).click();
        Thread.sleep(1000);
    }

    //9、菜单-换背景
    @Test
    public void testBackground() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"更多选项\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/content")).click();
        Thread.sleep(1000);
    }

    //10、菜单-音乐
    @Test
    public void testMusic() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"更多选项\"")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"关闭/开启音乐\"")).click();
        Thread.sleep(1000);
    }
	
	//11、明细-添加话费支出
	@Test
    public void testadd1() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/mx")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("话费1");
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
    }


    //12、明细-添加吃饭支出
    @Test
    public void testadd3() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/mx")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/ll_cf")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("吃饭");
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
    }

    //13、明细-添加购物支出
     @Test
    public void testadd2() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/mx")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/iv_gw")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("购物");
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
    }

    //14、明细-添加其他支出
     @Test
    public void testadd4() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/mx")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/ll_qt")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("其他");
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
    }

    //15、明细——工资收入
   @Test
    public void testadd5() throws InterruptedException {
		Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("工资");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_3")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_4")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
    }

    //16、明细——津贴收入
   @Test
    public void testadd6() throws InterruptedException {
		Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/ll_jt")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("津贴");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_3")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
    }

    //17、明细——红包收入
    @Test
    public void testadd7() throws InterruptedException {
		Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/ll_hb")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("红包");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
    }

    //18、明细——其他收入
    @Test
    public void testadd8() throws InterruptedException {
		Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:test/\"收入\"")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/ll_qt")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("其他");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
    }
	//19、图表——收入
    @Test
    public void testSr() throws InterruptedException {
		Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/tb")).click();
        Thread.sleep(1000);
		device.findObject(By.res("com.lyc.cashbook:id/btn_sr")).click();
    }
    //20、图表-支出
    @Test
    public void testSr() throws InterruptedException {
		Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_zc")).click();
    }
    @After
    public  void quite(){
        device.pressBack();
    }



}